﻿using System;
using System.Collections.Generic;

namespace Kang.ExtendMethod
{
    public static class EnumeratorExtendMethod
    {
        /// <summary>
        /// 安全方法，迭代并执行方法
        /// </summary>
        /// <param name="iterator">需要循环的迭代器</param>
        /// <param name="action">需要迭代执行的方法</param>
        public static void ForEach<T>(this IEnumerator<T> iterator, Action<T> action)
        {
            if (iterator == null)
            {
                return;
            }
            if (action == null)
            {
                return;
            }
            while (iterator.MoveNext())
            {
                action(iterator.Current);
            }
        }
    }
}
